package com.domain.pojo;

import com.common.exception.CustomException;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
 * @author 大忽悠
 */
@AllArgsConstructor
@NoArgsConstructor
public enum SeatStation {
    WINDOW_SEAT(0),HALLWAY(1),MIDDLE(2);

    private Integer seq;

    /**
     * @param seatInfo
     * @param seatHobby
     * @return 根据用户规定位置查找座位,如果找到了返回座位号,否则返回null,返回null表示采用随机分配
     */
    public static Integer choseOneSeatByStation(String seatInfo, Integer seatHobby) {
         if(!seatHobbyCheck(seatHobby)){
             return null;
         }
         //遍历查找每个座位
        char[] seatArray = seatInfo.toCharArray();
        for (int i = 0; i < seatArray.length; i++) {
              if(((i%3)==seatHobby) && seatArray[i]=='0'){
                  return i;
              }
        }
        return null;
    }

    private static boolean seatHobbyCheck(Integer seatHobby) {
        if(seatHobby<0 || seatHobby>2){
            return Boolean.FALSE;
        }
        return Boolean.TRUE;
    }

    public static Integer choseByRandom(String seatInfo) {
        char[] seatArray = seatInfo.toCharArray();
        for (int i = 0; i < seatArray.length; i++) {
            if(seatArray[i]=='0'){
                return i;
            }
        }
        throw new CustomException("没有剩余空位可供选择","没有剩余空位可供选择");
    }
}
